package com.twinkle.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.twinkle.dao.MenuMapper;
import com.twinkle.model.Menu;
import com.twinkle.model.MenuTree;
import com.twinkle.service.MenuService;
import com.twinkle.utils.JqgridUtil;
import com.twinkle.utils.MenuUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

//import com.google.gson.Gson;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
	private MenuMapper mapper;
	@Autowired
	private JqgridUtil jqgridUtil;
    
//	@Autowired
//    private Gson gson;

	@Override
	public String getAllUserMenu() {
		List<Menu> menuList = mapper.selectList(null);
		List<MenuTree> menuTreeList = new ArrayList<>();
		for (Menu menu : menuList) {
			Integer menuid = menu.getId();
			Integer levels = menu.getLevels();
			Integer parentid = menu.getParentid();

			if (levels == 1) {
				menuTreeList.add(new MenuTree(menuid,
						JSONObject.toJSONString(menu),
						0));
			} else {
				menuTreeList.add(new MenuTree(menuid,
						JSONObject.toJSONString(menu),
						parentid));
			}
		}

		//获取目录树
		List<MenuTree> collect = menuTreeList.stream().filter(m -> m.getParentId() == 0).map(
				(m) -> {
					m.setChildList(MenuUtil.getChildrens(m, menuTreeList));
					return m;
				}
		).collect(Collectors.toList());
		return JSONObject.toJSONString(collect);
	}

	@Override
	public Map<String, List<Menu>> getUserMenu() {
		return null;
	}

	@Override
	public String menuTreeData() {
		return null;
	}

	@Override
	public String getAllMenuJson(int page, int count) {
		return null;
	}

	@Override
	public String MenuListForUserAdd() {
		return null;
	}

	@Override
	public String addMenu(Menu menu) {
		return null;
	}

	@Override
	public String modifyMenu(Menu menu) {
		return null;
	}

	@Override
	public String deleteMenu(String id) {
		return null;
	}

	@Override
	public List<Menu> getAllMenu() {
		return null;
	}


}
